package com.nitramf.catchmystream.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * Represent a Twitter account (using OAuth token)
 * @author martinfilliau
 */
@Entity
@NamedQueries({
    @NamedQuery(name=TwitterAccount.QUERY_FIND_ALL_ACTIVATED, query="SELECT t FROM TwitterAccount AS t WHERE t.activated = true")
})
public class TwitterAccount extends Subscription implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Basic
    private String userName;
    
    @Basic
    private String token;

    @Basic
    private String tokenSecret;

    @Basic
    private Boolean activated;


    /* Queries */

    /**
     * Find all activated Twitter accounts
     */
    public static final String QUERY_FIND_ALL_ACTIVATED = "TwitterAccount.findAllActivated";


    /* GETTERs and SETTERs */

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getTokenSecret() {
        return tokenSecret;
    }

    public void setTokenSecret(String tokenSecret) {
        this.tokenSecret = tokenSecret;
    }

    public Boolean isActivated() {
        return activated;
    }

    public void setIsActivated(Boolean activated) {
        this.activated = activated;
    }


    /* Overriden methods */

    @Override
    public int hashCode() {
        int hash = 0;
        hash += ( id != null ? id.hashCode() : 0 );
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!( object instanceof TwitterAccount )) {
            return false;
        }
        TwitterAccount other = (TwitterAccount) object;
        if (( this.id == null && other.id != null ) || ( this.id != null && !this.id.equals(other.id) )) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nitramf.catchmystream.entities.TwitterAccount[id=" + id + "]";
    }

}
